<!-- 注册页面 -->
<template>
	<view>
		<view class="overall">
			<image src="../../static/login-icon/logo.png" class="login-icon"></image>
		</view>
		<view class="login">
			<form @submit="formsumit">
				<input type="text" placeholder="手机号码" class="input" name="phone">
				<input type="safe-password" placeholder="请输入密码" class="input" name="password">
				<input type="text" placeholder="请再次输入密码" class="input" name="password_two">
				<input type="text" placeholder="邀请人邀请码 (选填)" class="input" name="invite">
				<button class="input register" form-type="submit">立即开户</button>
			</form>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			};
		},
		methods:{
			notification(title){
				uni.showModal({
					title:title,
					showCancel:false
				});
			},
			formsumit(e){
				let request ='http://5f87e60b.r10.cpolar.top';
				let reg = /^1[3-9]{1}[0-9]{9}$/;
				let phone =e.detail.value.phone;
				let password =e.detail.value.password;
				let password_two =e.detail.value.password_two;
				let invite =e.detail.value.invite;
				if(phone.length==0){
					this.notification('请您填写手机号码');
				}else if(phone.length!==0 && reg.test(phone)!==true){
					this.notification('请输入正确的手机号码');
				}else if(phone.length!==0 && reg.test(phone)==true && password.length==0 || password_two.length==0){
					this.notification('请输入您的密码');
				} else if(password.length!==0 && password_two.length !== 0 && password !== password_two){
					this.notification('两次输入的密码不正确');
				}else if(password.length!==0 && password == password_two && reg.test(phone)==true){
					console.log('123')
					uni.request({
						url:'http://7dc52401.r10.cpolar.top/api/user/register',
						method:'POST',
						data:{
							"mobile":phone,
							"password":password
						},
						success(res) {
							if(res.statusCode == 200){
								let token =res.data.data.userinfo.token;
								uni.setStorageSync("token",token);
							}
							else{
								console.log(res);
								this.notification('请重试');
							}
						}
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.overall{
	width: 100%;
	height: 17.25rem;
	background: url("../../static/login-icon/login_bg.png") no-repeat;
	background-size:100% 11rem;
	display: flex;
	align-items: center;
	flex-direction: column-reverse;
	}
	.login-icon{
		width: 7.199998560000288rem;
		height: 7.199998560000288rem;
	}
	.login{
		width: 100%;
		height: 32.0399999993592rem;
		margin-top: 1.7999999964rem;
	}
	.input{
		width: 18.18rem;
		height: 3rem;
		border:  0.0599999988rem solid #f2f2f2;
		margin: 0rem auto;
		border-radius: 2rem;
		padding-left: 1.1999999999976rem;
		box-sizing: border-box;
		margin-bottom: 0.77999999844rem;
		color: #282828;
		font-size: 13px;
	}
	.button{
		background-color: #ff4c3e;
		color: #f2f2f2;
		font-size: 1.2rem;
		line-height: 3rem;
	}
	.register{
		background-color: transparent;
		border: 0.0599999988rem solid #ff4c3e;
		color: #ff4c3e;
		font-size: 1.2rem;
		line-height: 3rem;
	}
	.br{
		width: 100%;
		text-align: center;
		margin-bottom: 0.599998rem;
		color: #999999;
	}
</style>
